<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 */
class Product
{
    /**
     * @Groups({"product"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Groups({"product"})
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     */
    private $user;

    /**
     * @Groups({"product"})
     * @ORM\ManyToOne(targetEntity="App\Entity\Shop", inversedBy="products")
     * @ORM\JoinColumn(nullable=false)
     */
    private $shop;

    /**
     * @Groups({"product"})
     * @ORM\ManyToOne(targetEntity="App\Entity\Category")
     */
    private $cat1;

    /**
     * @Groups({"product"})
     * @ORM\ManyToOne(targetEntity="App\Entity\Category")
     */
    private $cat2;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $cover;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $subTitle;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="float")
     */
    private $price;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $unit;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="text", nullable=true)
     */
    private $intro;

    /**
     * @Groups({"product"})
     * @ORM\Column(type="array", nullable=true)
     */
    private $pics = [];

    /**
     * @Groups({"product"})
     * @ORM\OneToOne(targetEntity="App\Entity\ProductStatistic", mappedBy="product", cascade={"persist", "remove"})
     */
    private $statistic;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getShop(): ?Shop
    {
        return $this->shop;
    }

    public function setShop(?Shop $shop): self
    {
        $this->shop = $shop;

        return $this;
    }

    public function getCat1(): ?Category
    {
        return $this->cat1;
    }

    public function setCat1(?Category $cat1): self
    {
        $this->cat1 = $cat1;

        return $this;
    }

    public function getCat2(): ?Category
    {
        return $this->cat2;
    }

    public function setCat2(?Category $cat2): self
    {
        $this->cat2 = $cat2;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCover(): ?string
    {
        return $this->cover;
    }

    public function setCover(?string $cover): self
    {
        $this->cover = $cover;

        return $this;
    }

    public function getSubTitle(): ?string
    {
        return $this->subTitle;
    }

    public function setSubTitle(?string $subTitle): self
    {
        $this->subTitle = $subTitle;

        return $this;
    }

    public function getPrice(): ?float
    {
        return $this->price;
    }

    public function setPrice(float $price): self
    {
        $this->price = $price;

        return $this;
    }

    public function getUnit(): ?string
    {
        return $this->unit;
    }

    public function setUnit(?string $unit): self
    {
        $this->unit = $unit;

        return $this;
    }

    public function getIntro(): ?string
    {
        return $this->intro;
    }

    public function setIntro(?string $intro): self
    {
        $this->intro = $intro;

        return $this;
    }

    public function getPics(): ?array
    {
        return $this->pics;
    }

    public function setPics(?array $pics): self
    {
        $this->pics = $pics;

        return $this;
    }

    public function getStatistic(): ?ProductStatistic
    {
        return $this->statistic;
    }

    public function setStatistic(ProductStatistic $statistic): self
    {
        $this->statistic = $statistic;

        // set the owning side of the relation if necessary
        if ($statistic->getProduct() !== $this) {
            $statistic->setProduct($this);
        }

        return $this;
    }
}
